package com.zdxlz.desensitize.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author LySoY
 */
public class KeyUtil {
    private KeyUtil() {}

    public static String generateKey(String... strings) {
        StringBuilder sb = new StringBuilder();
        for (String s : strings) {
            sb.append(s);
        }
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(sb.toString().getBytes());
            byte[] digest = md.digest();
            StringBuilder keyBuilder = new StringBuilder();
            for (byte b : digest) {
                keyBuilder.append(String.format("%02x", b & 0xff));
            }
            return keyBuilder.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return sb.toString();
        }
    }
}
